    <div class="container-fluid" id="LG">
    <div class="row-fluid">
        <div class="span12">
            <% $.et.load('template/menu.et.html', data) %>
            <div style="margin-top: 10px;" class="panel panel-default">
			<div class="panel-heading">
				<h2 class="panel-title">Minecraft服务器状态</h2>
			</div>
			<div class="panel-body">
				<div class="form-group">
					<textarea id="message" class="form-control" readonly="readonly" rows="15"></textarea>
				</div>
				<div class="form-group">
					<input id="send_message" onkeypress="R.sendmessage(event)" placeholder="输入指令后按回车即可发送指令到服务器" class="form-control"></input>
				</div>
				<div class="btn-group btn-group-justified">
					<a class="btn btn-default" href="javascript:;" onclick="R.start()">开服</a>
					<a class="btn btn-default" href="javascript:;" onclick="R.restart();">重启</a>
					<a class="btn btn-default" href="javascript:;" onclick="$('#close_modal').modal('show');">关服</a>
				</div>
			</div>
			<div class="panel-footer"><% $.et.load('template/version.et.html', data) %></div>
			</div>
        </div>
    	</div>
	</div>
	<!-- 模态窗口 -->
	<div class="modal fade" id="close_modal" tabindex="-1" role="dialog" 
	   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
	      <div class="modal-content">
	         <div class="modal-header">
	            <button type="button" class="close" 
	               data-dismiss="modal" aria-hidden="true">
	                  &times;
	            </button>
	            <h4 class="modal-title" id="myModalLabel">
	               	提示
	            </h4>
	         </div>
	         <div class="modal-body">
				请选择关闭服务器的方式<br />
				<span style="color: red;">
					注：强制关闭服务器可能会导致服务器回档
				</span>
	         </div>
	         <div class="modal-footer">
	            <button onclick="R.stop()" type="button" class="btn btn-primary">
	              	正常关服
	            </button>
	            <button onclick="R.termination()" type="button" class="btn btn-danger">
	              	强制关服
	            </button>
	            <button type="button" class="btn btn-default" 
	               data-dismiss="modal">取消
	            </button>
	         </div>
	      </div>
	     </div>
	</div>
    <script>
        R.g_uuid = '';
        R.restart_flag = false;
        R.isstop = false;
        <% if(data.username == null){%>
            R.notLogin();
        <% } %>
        //初始化拉取消息
        webmcs.server.getMessage(undefined, function(data){
            if (typeof(data.message)=="string"){
                R.addMessage(data.message);
                g_uuid = data.uuid;
            }
            if (data.status){
                R.addMessage("[状态]服务器运行中...\n");
                R.getmessage(g_uuid);
            } else {
                R.addMessage("[状态]服务器不在运行\n");
            }
        });
	      	
        R.addMessage = function(text){
		    var tmp = $("#message").val();
			if (tmp.length > 20000){
			    tmp = "";
            }
		    tmp += text;
		    $("#message").val(tmp);
		    $("#message").scrollTop(99999);
	    }
        
        R.getmessage = function(uuid){
			uuid = uuid==undefined?"":uuid;
			webmcs.server.getMessage(uuid,function(data){
                if (data.status && typeof(data.message)=="string"){
			    	R.addMessage(data.message);
			    }
                if (!R.isstop){
                    setTimeout(function(){
                        if (R.restart_flag || data.status){
                            R.getmessage(data.uuid);
                            R.restart_flag = false;
                        }else{
                            if (data.msg)
                                R.addMessage("[系统]接口访问异常，原因：" + data.msg + "\n");
                            else
                                R.addMessage("[系统]服务器已关闭\n");
                            R.g_uuid = data.uuid;
                        }
                    },500);
                }
            });
		}

	    R.start = function(){
			webmcs.server.start(function(data){
                if (data.status){
                    R.addMessage("[系统]服务器启动中...\n");
                    R.getmessage(g_uuid);
                }else{
                    switch(data.msg){
                        case "NOTLOGIN":
                            R.notLogin();
                            break;
                        case "ALREADYSERVER":
                            R.addMessage("[系统]服务器已启动，请不要重复开服！\n");
                            break;
                        case "JARERROR":
                            R.addMessage("[系统]服务器核心文件（JAR）未设置，无法开服，请先设置！\n");
                            break;
                        case "PROCESSERROR":
                            R.addMessage("[系统]JAVA设置错误，无法开服，请先设置！\n");
                            break;
                        default:
                            R.addMessage("[系统]" + data.msg + "\n");
                            break;
                    }
                }
            });
		}
        R.stop = function(){
            webmcs.server.stop(function(data){
                if (data.status){
                    R.addMessage("[系统]服务器关闭中，请稍等...\n");
                }else{
                    switch(data.msg){
                        case "NOTLOGIN":
                            R.notLogin();
                            break;
                        case "SERVERNOTRUN":
                            R.addMessage("[系统]服务器未启动，无法关闭！\n");
                            break;
                        case "UNKNOWNERROR":
                            R.addMessage("[系统]发生未知错误发送指令失败，请检查后台报错并反馈给作者！\n");
                            break;
                        default:
                            R.addMessage("[系统]" + data.msg + "\n");
                            break;
                    }
                }
                $('#close_modal').modal('hide');
            });
        }
        R.termination = function(){
            webmcs.server.termination(function(data){
                if (data.status){
                    R.addMessage("[系统]服务器已被强制关闭！\n");
                }else{
                    switch(data.msg){
                        case "NOTLOGIN":
                            R.notLogin();
                            break;
                        case "SERVERNOTRUN":
                            R.addMessage("[系统]服务器未启动，无法强制关闭！\n");
                            break;
                        default:
                            R.addMessage("[系统]" + data.msg + "\n");
                            break;
                    }
                }
                $('#close_modal').modal('hide');
            });
        }
            
        R.sendmessage = function(event){
            event = (event) ? event : ((window.event) ? window.event : "") 
            var key = event.keyCode?event.keyCode:event.which;
            if (key == 13){
                webmcs.server.sendMessage($("#send_message").val(),function(data){
                    if (data.status) {
                        $("#send_message").val("");
                    }else{
                        switch(data.msg){
                            case "NOTLOGIN":
                                R.notLogin();
                                break;
                            case "SERVERNOTRUN":
                                R.addMessage("[系统]服务器未启动，无法发送指令给服务器!\n");
                                break;
                            case "UNKNOWNERROR":
                                R.addMessage("[系统]发生未知错误发送指令失败，请重试，如果重复出现问题请反馈给作者！\n");
                                break;
                            default:
                                R.addMessage("[系统]" + data.msg + "\n");
                                break;
                        }
                    }
                });
            }
        }
        
        R.restart = function(){
            R.addMessage("[系统]服务器重启中，请稍后...\n");
            restart_flag = true;
            webmcs.server.restart(function(data){
                if (data.status){
                    R.addMessage("[系统]重启执行成功，服务器启动中...\n");
                }else{
                    switch(data.msg){
                        case "NOTLOGIN":
                            R.notLogin();
                            break;
                        case "SERVERNOTRUN":
                            R.addMessage("[系统]服务器未启动，无法进行重启操作！\n");
                            break;
                        case "TIMEOUT":
                            R.addMessage("[系统]服务器关闭超时，请检查服务器运行状态。\n");
                            break;
                        case "NETERROR":
                            R.addMessage("[系统]网络异常，重启操作请求失败。\n");
                            break;
                        default:
                            R.addMessage("[异常]" + data.msg + "\n");
                            break;
                    }                 
                }
            });
        }
    </script>